﻿#Region "IMPORTS"

Imports DAO

#End Region

Public Class MateriaPrimaDao
    Inherits DAO(Of MateriaPrima)


#Region "CONSTRUTOR(S)"

    Public Sub New()
        MyBase.New()
    End Sub

#End Region

#Region "METODOS ABSTRATOS"

    Protected Overrides Sub ValidarInsert(modelo As MateriaPrima)

        Dim NHQL As String = "from MateriaPrima where Descricao  = '" & modelo.Descricao & "'"
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Materia Prima com esse Nome")
        End If
    End Sub

    Protected Overrides Sub ValidarDelete(modelo As MateriaPrima)

    End Sub

    Protected Overrides Sub ValidarUpdate(ByVal modelo As MateriaPrima)

        Dim NHQL As String = "from MateriaPrima as mt where mt.Descricao  = '" & modelo.Descricao & "' AND mt.MateriaPrimaId != " & modelo.MateriaPrimaId
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe uma Materia Prima com esse Nome")
        End If

    End Sub

#End Region
End Class
